iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 19
0
自我挑戰組

各種筆記系列 第 19

[Kata] Clojure - Day 19

  • 分享至 

  • xImage
  •  

Watermelon

Pete and Billy are great fans of even numbers, that's why they want to divide the number of watermelons in such a way that each of the two parts consists of an even number of watermelons. However, it is not obligatory that the parts are equal.

Example: the boys can divide a stack of 8 watermelons into 2+6 melons, or 4+4 melons.

切西瓜,只能切成偶數加偶數,若給予的數字不能分為偶數加偶數,則回傳 false

Solution

(ns kata)
(defn divide [n]
  (cond
    (= n 2) false
    (= 0 (rem n 2)) true 
    :else false)
)

Complementary DNA

翻譯 DNA

Solutions

(ns complementary-dna)

(defn dna-strand [dna]
  (clojure.string/replace dna #"A|T|C|G" {"A" "T" "T" "A" "C" "G" "G" "C"})
)
(ns complementary-dna)

(defn dna-strand [dna]
    (apply str (map {\A \T \C \G \G \C \T \A} dna)))

上一篇
[Kata] Clojure - Day 18
下一篇
[Kata] Clojure - Day 20
系列文
各種筆記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言